<html>
<head><meta charset="utf-8"><title>disable example with cfg · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/disable.20example.20with.20cfg.html">disable example with cfg</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="207787184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/disable%20example%20with%20cfg/near/207787184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Simmons <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/disable.20example.20with.20cfg.html#207787184">(Aug 23 2020 at 19:16)</a>:</h4>
<p>I'm wondering if maybe I've missed something. Is there any way to disable an example with a cfg? e.g. if the example depends on some feature, and the feature is missing.</p>
<p>Doing the simple obvious thing with <code>#![cfg(not(feature = "blah"))]</code> at the top of the file doesn't really work, because it just makes the compiler complain about a missing main function in the module.</p>
<p>I'd rather not have to split the example out from the rest and treat it specially, but I guess that's the only option here?</p>



<a name="207787266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/disable%20example%20with%20cfg/near/207787266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/disable.20example.20with.20cfg.html#207787266">(Aug 23 2020 at 19:19)</a>:</h4>
<p>In headcrab we are using a cfg'ed module and a main function that either calls a function in the mod or panics.</p>



<a name="207788995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/disable%20example%20with%20cfg/near/207788995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/disable.20example.20with.20cfg.html#207788995">(Aug 23 2020 at 20:05)</a>:</h4>
<p><a href="https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-required-features-field">https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-required-features-field</a></p>



<a name="207789065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/disable%20example%20with%20cfg/near/207789065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/disable.20example.20with.20cfg.html#207789065">(Aug 23 2020 at 20:07)</a>:</h4>
<p>So you have to list the example explicitly and specify its features. Not sure if that's the kind of splitting you didn't want though.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>